Repository navigation
feat(wan): run Wan 2.2 attention on SageAttention when enabled - #9665
Merged
Merged
Conversation
With `attention_backend: sage`, Wan 2.2 image and video denoising enter the SageAttention scope. RTX 4090, Wan 2.2 TI2V-5B GGUF Q8 at 1280×704, 121 frames: 380.9 s → 247.9 s, peak VRAM unchanged, no added flicker.
6 of 7 tasks
# Conflicts: # docs/src/content/docs/configuration/Optimization/sage-attention.mdx
Pfannkuchensack
marked this pull request as ready for review
October 12, 2026 20:44
1 task done
At 832×480 with 81 frames SageAttention halves denoising (121.5 s → 60.9 s); at 1280×720 a 24 GB GPU is already full with PyTorch's attention and it got slower (293 s → 662 s), tracked in invoke-ai#9831.
lstein
enabled auto-merge
October 16, 2026 15:51
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
Stacked PR 8 of 8: merge after #9664. It targets
main, so until the PRs before it merge, its diff also shows their commits and the merges that carry them forward. This PR's own changes are two commits,cd6e58c52d(the scope) and3d1a8b49f0(the A14B measurements in the docs).Summary
With
attention_backend: sage, Wan 2.2 denoising ("Denoise - Wan 2.2" and "Denoise Video - Wan 2.2") enters the SageAttention scope from #9657, so its eligible attention calls run on SageAttention. Everything else stays on PyTorch SDPA, and the defaultautois unchanged. The docs page lists Wan 2.2 under Supported models.Related Issues / Discussions
Stacked on #9657 (SageAttention backend) and #9664, the PR before it. Related: #9529, which asks for SageAttention to speed up Wan 2.2 A14B at 1280×720 on a 24 GB GPU. This PR does not close it: at that size a 24 GB GPU is already full with PyTorch's attention, and SageAttention made it slower (see QA). #9831 tracks that, together with Wan's missing working-memory estimate.
QA Instructions
Wan 2.2 TI2V-5B GGUF Q8 through "Denoise Video - Wan 2.2", model loaded, three arms per seed as described in #9657:
All 120 attention calls per step ran on SageAttention, including the text cross-attention with 512 text tokens; none fell back.
Accuracy on real activations, every call of step 0 (120 calls): worst relative L2 0.076, in the text cross-attention; the heads with low cosine there contribute almost nothing (output norm 0.08 against a median of 5.7).
Wan 2.2 T2V A14B (GGUF Q4_K_M, both experts, 4-step Lightning LoRA V1.1, 81 frames, partial loading on,
device_working_mem_gb: 10, which A14B needs on 24 GB without SageAttention too, see [bug]: Wan 2.2 A14B at 720p does not fit 24 GB (no working-memory estimate); SageAttention makes the overflow slower #9831), denoising only:At 1280×720 the GPU is already full with SDPA; SageAttention's quantized copies (~1.2 GB more than SDPA per call) push it over, and Windows moves memory to shared system memory instead of raising out-of-memory, so its fallback never triggers. The docs row states both results.
"Denoise - Wan 2.2" (image): TI2V-5B at 1280×704 compresses each image to 880 tokens, below the 1536-token threshold, so all 2400 calls of a measured generation stayed on SDPA.
The timings and LPIPS come from the measurement prototype, which still used
sageattn()'s default K smoothing; the selection feat(attention): add opt-in SageAttention backend for diffusion models #9657 ships is faster per call.To try it: install SageAttention as the docs page from #9657 describes, set
attention_backend: sage, restart and generate with Wan 2.2. The first generation logsSageAttention ... serves diffusion-model attention on cuda:0 (...)with the GPU and kernel name, and withlog_level: debugevery generation logs how many calls ran on SageAttention and why the others did not. Withattention_backend: autothe output is bit-identical tomain.Checks: ruff clean;
pytest tests/app/invocationspasses with the whole stack applied (2090 passed). No call-site test was added: this change only enters the scope, whose behavior #9657 tests.Review
No material findings for this call site. Remaining: Wan 2.2 A14B at 1280×720 on a 24 GB GPU is slower with SageAttention (#9831).
Compatibility / Rollout
Merge after #9664. No API or persisted-state change; only
attention_backend: sagebehaves differently.Checklist
What's Newcopy (if doing a release after this PR)